<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * CMS
 */
namespace CMS\Controller;
use Common\Controller\AdminController;

/**
 * 控制台
 */
class ConsoleController extends AdminController{
	
	/**
	 * 仪表盘
	 */
    public function Dashboard(){
    

		common_public()->assign_page('仪表盘');
		
		$num_model = $this->getNum('CMS_MODEL');
		$num_article = $this->getNum('CMS_ARTICLE');
		$num_channel = $this->getNum('CMS_CHANNEL');
		$num_page = $this->getNum('CMS_PAGE');
		$num_menu = $this->getNum('CMS_MENU');
		$num_conf = $this->getNum('CMS_CONF');
		$num_draft = $this->getNum('CMS_DRAFT');
		
		
		$this->Upload();
		$this->UploadType();
		
		$this->assign('num_model',$num_model);
		$this->assign('num_article',$num_article);
		$this->assign('num_channel',$num_channel);
		$this->assign('num_page',$num_page);
		$this->assign('num_menu',$num_draft);
		
		$this->assign('num_conf',$num_conf);
		$this->assign('num_draft',$num_draft);
		
		$m_cms_content = M('cms_content');
		$m_common_user = M('common_user');
		
		$map['status'] = array('in','1,2');
		$map['type'] = get_cms_model_conf('CMS_ARTICLE');
		
		$list = $m_cms_content->where($map)->limit(15)->select();
	
		
		//查询关联信息
		foreach($list as $i=>$k){
			
			$fmap['id'] = $list[$i]['form_id'];
			$fdata = $m_cms_content->where($fmap)->find();
			$umap['id'] = $list[$i]['uid'];
			
			$udata = $m_common_user->where($umap)->find();
			
			
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
			
		
		}
		//赋值
		$this->assign('list',$list);
		
		$this->display();
	}
	
	/**
	 * 菜单汇总
	 */
	public function getNum($type){
    
		$m_cms_content = M('cms_content');
		
		$map['type'] = get_cms_model_conf($type);
		$map['status'] = array('in','1,2');
		
		$num = $m_cms_content->where($map)->count();
		
		return $num;
		
		
	}
	
	/**
	 * 上传文件
	 */
	public function Upload(){
    
		$m_common_upload = M('common_upload');
		
		$upload_num = $m_common_upload->where('status=1')->count();
		
		$this->assign('upload_num', $upload_num);
		
		
	}
	
	/**
	 * 上传文件类型
	 */
	public function UploadType(){
    
		$m_common_upload_type = M('common_upload_type');
		
		$upload_type_num = $m_common_upload_type->where('status=1')->count();
		
		$this->assign('upload_type_num', $upload_type_num);
		
		
	}
	
	
}